package com.ldq.imooc.basics.multiThread;

/**
 * @Author : 李道泉
 * @Description :
 * @Date : 2018/4/24 10:47
 * @Modified by :
 */

class MyThread extends Thread {

    //5张火车票
    private int ticketsCount = 5;
    //模拟售票窗口，线程
    private String name;

    public MyThread(String name) {
        this.name = name;
    }

    @Override
    public void run() {

        while (ticketsCount > 0) {
            //如果有票，就卖掉一张
            ticketsCount--;
            System.out.println(name + "：卖了一张票，余票为：" + ticketsCount);

        }
    }
}

public class TicketsThread {

    public static void main(String[] args) {
        //模拟三个窗口线程
        MyThread win1 = new MyThread("窗口1");
        MyThread win2 = new MyThread("窗口2");
        MyThread win3 = new MyThread("窗口3");

        //启动线程开始模拟卖票
        win1.start();
        win2.start();
        win3.start();
    }
}
